package com.computec.core.imagenes.listener;

/*
 * ContextListener.java
 *
 * Created on 21 de noviembre de 2006, 11:54 AM
 */
import com.computec.core.imagenes.base.constantes.ConstantesGenerales;
import com.computec.core.imagenes.dao.ImagenesDAO;
import com.computec.core.imagenes.delegate.ImagenesDelegate;
import com.computec.core.imagenes.exception.ImagenesException;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;

/**
 *
 * @author  jlperea
 * @version
 *
 * Web application lifecycle listener.
 */

public class ContextListenerCopiadoImagenes implements ServletContextListener {
    /**
     * ### Method from ServletContextListener ###
     * 
     * Called when a Web application is first ready to process requests
     * (i.e. on Web server startup and when a context is added or reloaded).
     * 
     * For example, here might be database connections established
     * and added to the servlet context attributes.
     */
    public void contextInitialized(ServletContextEvent evt) 
    {
        System.out.println("--------------------------------------------------");
        System.out.println("ContextListenerCopiadoImagenes: contextInitialized: Inicio - ");
        //Para que inicialice las constantes
        ConstantesGenerales constantesGenerales = ConstantesGenerales.getInstance();
        
        try 
        {
            procesarBloqueCopiadoImagenes();             
        }
        catch (Exception e) 
        {
            e.printStackTrace();
        }
        System.out.println("ContextListenerCopiadoImagenes: contextInitialized: Termino - ");
        System.out.println("--------------------------------------------------");
    }

    /**
     * ### Method from ServletContextListener ###
     * 
     * Called when a Web application is about to be shut down
     * (i.e. on Web server shutdown or when a context is removed or reloaded).
     * Request handling will be stopped before this method is called.
     * 
     * For example, the database connections can be closed here.
     */
    public void contextDestroyed(ServletContextEvent evt) 
    {        
    }
    
    public void procesarBloqueCopiadoImagenes() throws ImagenesException
    {
        ImagenesDelegate imagenesPlusDelegate = new ImagenesDelegate();           
        imagenesPlusDelegate.procesarBloqueCopiadoImagenes();        
    }
}
